package com.golden.order02.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.golden.order02.dao.OrderSalePerformanceMapper;
import com.golden.order02.domain.OrderSalePerformanceDO;
import com.golden.order02.domain.ResultDO;
import com.golden.order02.entity.OrderSalePerformance;
import com.golden.order02.query.OrderSalePerformanceExample;

@Service
public class OrderSalePerformanceServiceImpl implements OrderSalePerformanceService{
	
	@Autowired
	OrderSalePerformanceMapper orderSalePerformanceMapper;
	
	public ResultDO<OrderSalePerformanceDO> get( Integer id){
		ResultDO<OrderSalePerformanceDO> result=new ResultDO<OrderSalePerformanceDO>();
		BaseServiceImpl<OrderSalePerformanceDO,OrderSalePerformance> bi=new BaseServiceImpl<>();
		OrderSalePerformanceDO oo=new OrderSalePerformanceDO();
		
		try {
			OrderSalePerformance selectByPrimaryKey = orderSalePerformanceMapper.selectByPrimaryKey(id);
			OrderSalePerformanceDO t = bi.getT(selectByPrimaryKey, oo);
			result.setData(t);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_QUERY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_QUERY_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<List<OrderSalePerformanceDO>> query( OrderSalePerformanceExample example){
		ResultDO<List<OrderSalePerformanceDO>> result=new ResultDO<List<OrderSalePerformanceDO>>();
		BaseServiceImpl<OrderSalePerformanceDO,OrderSalePerformance> bi=new BaseServiceImpl<>();
		OrderSalePerformanceDO oo=new OrderSalePerformanceDO();
		try {
			List<OrderSalePerformance> selectByExample = orderSalePerformanceMapper.selectByExample(example);
			List<OrderSalePerformanceDO> tList = bi.getTList(selectByExample, oo);
			result.setData(tList);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_QUERY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_QUERY_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<OrderSalePerformanceDO> add( OrderSalePerformanceDO beanDO){
		ResultDO<OrderSalePerformanceDO> result=new ResultDO<OrderSalePerformanceDO>();
		BaseServiceImpl<OrderSalePerformance, OrderSalePerformanceDO> bi=new BaseServiceImpl<>();
		OrderSalePerformance oi=new OrderSalePerformance();
		OrderSalePerformance t = bi.getT(beanDO, oi);
		try {
			int insert = orderSalePerformanceMapper.insert(t);
			if(insert<=0) {
				throw new Exception();
			}
			beanDO.setId(t.getId());
			result.setData(beanDO);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_ADD_ERROR);
			result.setErrorMsg(ResultDO.ORDER_ADD_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<Integer> delete( Integer id){
		ResultDO<Integer> result=new ResultDO<Integer>();
		try {
			int deleteByPrimaryKey = orderSalePerformanceMapper.deleteByPrimaryKey(id);
			if(deleteByPrimaryKey<=0) {
				throw new Exception();
			}
			result.setData(id);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_DELETE_ERROR);
			result.setErrorMsg(ResultDO.ORDER_DELETE_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<OrderSalePerformanceDO> modify( OrderSalePerformanceDO beanDO){
		ResultDO<OrderSalePerformanceDO> result=new ResultDO<OrderSalePerformanceDO>();
		BaseServiceImpl<OrderSalePerformance, OrderSalePerformanceDO> bi=new BaseServiceImpl<>();
		OrderSalePerformance oi=new OrderSalePerformance();
		OrderSalePerformance t = bi.getT(beanDO, oi);
		try {
			int insert = orderSalePerformanceMapper.updateByPrimaryKeySelective(t);
			if(insert<=0) {
				throw new Exception();
			}
			result.setData(beanDO);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_MODIFY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_MODIFY_MSG_ERROR);
		}
		return result;
	}
}
